home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11606 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: doors.informatik.uni-siegen.de!plrunu
  2. From: plrunu@informatik.uni-siegen.de (Runu Knips)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: HELP! On how to declare large arrays.
  5. Date: 15 Mar 1996 13:04:33 GMT
  6. Organization: University of Siegen
  7. Sender: plrunu@doors.informatik.uni-siegen.de (Runu Knips)
  8. Message-ID: <4ibpt1$br5@si-nic.hrz.uni-siegen.de>
  9. References: <lynch-1303962017180001@mac50.sask.trlabs.ca> <4ib40n$8of@moody.mchh.siemens.de>
  10. NNTP-Posting-Host: doors.informatik.uni-siegen.de
  11.  
  12. Well, easy. You're using C/C++, so you can declare your array the following way:
  13. (assuming you're using int. Replace it with any other data type if you want)
  14.  
  15.     int *arr[512];
  16.  
  17. Now construct the array with:
  18.  
  19.         for (int i = 512; i--;)
  20.         arr[i] = new int[128];
  21.  
  22. You can now use exactly the same syntax to access any array element in the
  23. array as if you had declared the array as int arr[512][128];
  24.  
  25. Nevertheless, you may want to use a #ifdef __MSDOS__ or such, for this
  26. solution is a little bit slower than the 2-dim array solution.
  27.  
  28. Ciao, Runu.
  29.  
  30.  
  31.